package org.sl.flvplayer.helper {

	/**
	 * Stack for keeping and processing operations like for example commands.</br>
	 * The default processing order is first in first out.
	 * 
	 * @package org.sl.flvplayer.helper
	 * @author Dan
	 * @version 
	 * @see org.sl.flvplayer.controls.PlayerLogic
	 */ 
	public class Stack extends Array {

		private var type : String;

		/**
		 * Sets the operation behavior to first in first out.
		 * 
		 * @param p_type operation type 
		 */
		public function Stack(p_type : String = "fifo") {
			super();
			type = p_type;
		}

		/**
		 * Indicates whether the stack is empty.
		 * 
		 * @return length of the stack
		 */
		public function isEmpty() : Boolean {
			return (this.length <= 0);
		}

		/**
		 * Adds a object to the stack.
		 * 
		 * @param p_item object
		 */
		public function addItem(p_item : *) : void {
			switch (type) {
				case "fifo":
					this.push(p_item);
					break;
			}
		}

		/**
		 * Processes the first object in stack and gets the next one.
		 * 
		 * @return removes the first object from the stack and returns that object
		 */
		public function getNext() : * {
			switch(type) {
				case "fifo":
					return this.shift();
			}
		}		
	}
}
